import Axios from 'axios'

export default {
    state: {
        games: [],
    },
    getters: {
        games: state => state.games,
    },
    mutations: {
        SET_GAMES(state, data) {
            state.games = data
        },
    },
    actions: {
        get_games({ commit }) {
            return new Promise((resolve, reject) => {
                Axios
                    .post('/game/list', {})
                    .then(res => {
                        for (let item of res.data.list) {
                            item.isDownloaded = false;
                            item.isDownloading = false;
                            item.percentage = 0;
                        }
                        commit('SET_GAMES', res.data.list)
                        resolve(res)
                    })
                    .catch(error => {
                        reject(error)
                    })
            })
        },
    }
}